﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ISODOC.Models.Request.DARDOC_DS>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Manager_App
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table class="tftable" style="width:95%">
           <tr style="background-color:#929097; color:White;"><td colspan="2"><h3> DAR No.   <%: Model._Docno %></h3></td></tr>
        
        <tr>
            <th style="width:30%">
                <h3>
                    ผู้ร้องขอ</h3>
            </th>
            <td>
                <%: Model._Empname %>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    ผู้จัดการแผนก.</h3>
            </th>
            <td>
                <%: Model._Mgrname %>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    ประเภทเอกสารและข้อมูล</h3>
            </th>
            <td>
                <%: Model._DOCTypenm %>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    หัวข้ออนุมัติ</h3>
            </th>
            <td>
                <%: Model._OPTTypenm %>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    เอกสารที่ต้องการอนุมัติ</h3>
            </th>
            <td>
          <a href="#" fileTempName="<%:Model._FileTemp%>"><%: Model._Filename %></a>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    รายละเอียด/เหตุผลของการอนุมัติ</h3>
            </th>
            <td>
            <p id="double-spaced" style="line-height: 150%;">
             <%: MvcHtmlString.Create( Model._Text .Replace("\n","<br />") ) %> <br />
               </p>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    ระบุความสัมพันธ์กับเอกสารอื่น</h3>
            </th>
            <td>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    Revision ก่อนหน้า</h3>
            </th>
            <td>
                <%: Model._Refrev %>
            </td>
        </tr>
    </table>
    <table  class="tftable" style="width:95%">
        <tr style="background-color:#929097; color:White;"><td colspan="2"><h3>Your Message</h3></td></tr>
        <tr>
            <td colspan="2">
                <textarea id="txtMsg" cols="108" rows="5"></textarea>
            </td>
        </tr>
        <tr>
            <td  style="border-right:0px;"> <input type="button" id="btnapv" value="Approve" class="btn" style="width:150px;"/>
            </td>
            <td style="text-align:right; border-left:0px;">
               <input type="button" id="btndis" value="Disapprove" class="btn" style="width:150px;"/>
            </td>
        </tr>
    </table>
    <br />
      <%: Html.Partial("_History",Model) %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <h2>
        ISO Document Request Form</h2>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">

    <script type="text/jscript">
        $(function () {
     
            $("a[fileTempName]").click(function () {
                var downloadUrl = '<%:Url.Action("Download") %>';
                var temp = $(this).attr("fileTempName");
                var file = $(this).text();
                var data = { fileName: file, fileTempName: temp };
                $.download(downloadUrl, data);
            });

            function valid_page() {
                if ($("#txtMsg").val().length <= 0) {
                    $().toastmessage('showErrorToast', 'กรุณาระบุข้อความของท่าน');
                    return false;
                }
                return true;
            }

            $("#btnapv").click(function () {
                if (valid_page == false) {
                    return;
                }
                var getUsersUrl = '<%= Url.Action("Manager_Save") %>';
                WAITINGDLG_show(imgWait);
                callScriptMethod(getUsersUrl, {
                    status: "1", darno: '<%: Model._Docno %>'
                , txt: $("#txtMsg").val(), txt_status: $(this).val()
                });
            })
            $("#btndis").click(function () {
                if (valid_page == false) {
                    return;
                }
                var getUsersUrl = '<%= Url.Action("Manager_Save") %>';
                WAITINGDLG_show(imgWait);
                callScriptMethod(getUsersUrl, { status: "-1", darno: '<%: Model._Docno %>'
                , txt: $("#txtMsg").val(), txt_status: $(this).val()
                });
            })

            function callScriptMethod(url, jsonObject, action, callback, async) {

                callback = callback || function () { };
                async = (async == null || async);

                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: url,
                    data: JSON.stringify(jsonObject),
                    dataType: "json",
                    async: async,
                    success: function (data) {

                        if (data.success != "0") {
                            //OK 
                            $().toastmessage('showSuccessToast', data.message);

                        } else $().toastmessage('showErrorToast', data.message);
                        WAITINGDLG_hide();
                    },
                    error: function (xhr, status, error) {
                        WAITINGDLG_hide();
                        var err = xhr.responseText;
                        alert(err.Message);
                    }

                });
                // 
            }
        });
</script>
</asp:Content>
